/* eslint-disable no-undef */
// eslint-disable-next-line no-unused-vars

class Watcher {
  constructor (vm, exp, cb) {
    this.cb = cb
    this.vm = vm
    this.exp = exp
    if (!this.nodeContent) {
      this.nodeContent = Watcher.nodeContent
      Watcher.nodeContent = null
    }
    this.value = this.get() // 将自己添加到订阅器的操作
  }
  update () {
    this.run()
  }
  run () {
    let value = null
    value = this.vm[this.exp]
    this.value = value
    this.cb(value, this.nodeContent)
  }
  get () {
    Dep.target = this // 暂存自己
    let value
    value = this.vm[this.exp] // 执行监听器里的get函数保存watcher
    Dep.target = null // 释放自己
    return value
  }
}

(function () {
  return Watcher
})()
